#include<cstdio>
#include"lesson111111.h"

File::File(char * const fname) {
	f = fopen(fname, "w");
	if (!f) throw "File could not be opened.";
}

File::~File() {
	if (f) close();
}

void File::close() {
	if (f) {
		fclose(f);
		f = 0;
	}
}

File & File::operator << (int i) {
	if (f) {
		fprintf(f, "%d", i);
	}
	return *this;
}

File & File::operator << (char const * s) {
	if (f) {
		fprintf(f, "%s", s);
	}
	return *this;
}

int main() {
	try {
		File f("./sample.txt");
		f << 100500;
		f << "\nThe quick brown fox jumped over a lazy dog.\n";
		std::cout << "All correct." << std::endl;
	}
	catch (char * const s) {
		std::cout << "Error:" << s << std::endl;
	}
	return 0;
}